//https://leetcode-cn.com/problems/middle-of-the-linked-list/solution/
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */
 //=============================================
 //===========方法三：快慢指针法
class Solution {
public:
    ListNode* middleNode(ListNode* head) 
    {
        ListNode * mid = head;
        ListNode * preNode = head->next;
        while(preNode)
        {
            mid = mid->next;
            if(preNode = preNode ->next)
            {
                preNode = preNode ->next;
            }
        }
        return mid;
    }
};